package br.upe.dsc.patdown.control;

public class PDWorkerInfo {

	private static long requestIdExecuting = -1;

	private static String commandInExecution;

	private static String brokerInfoExecuting;

	private static Object executionReference;

	public static boolean NEW_WORK = false;

	public static void willStartExecution(long requestId, String brokerInfoString, Object executionReference) {
		PDWorkerInfo.requestIdExecuting = requestId;
		PDWorkerInfo.brokerInfoExecuting = brokerInfoString;
		PDWorkerInfo.executionReference = executionReference;
	}

	public static boolean shouldStartNew(long requestId, String brokerPublicKey) {
		if (requestIdExecuting == -1) {
			return true;
		} else {
			if (brokerPublicKey != null && brokerPublicKey.equals(brokerInfoExecuting)) {
				return !(requestIdExecuting == requestId);
			} else {
				return true;
			}
		}
	}

	public static void clearInfo() {
		requestIdExecuting = -1;
		commandInExecution = null;
		brokerInfoExecuting = null;
		executionReference = null;
	}

	/**
	 * @return the commandInExecution
	 */
	public static String getCommandInExecution() {
		return commandInExecution;
	}

	/**
	 * @param commandInExecution
	 *            the commandInExecution to set
	 */
	public static void setCommandInExecution(String commandInExecution) {
		PDWorkerInfo.commandInExecution = commandInExecution;
	}

	/**
	 * @return the brokerInfoExecuting
	 */
	public static String getBrokerInfoExecuting() {
		return brokerInfoExecuting;
	}

	/**
	 * @param brokerInfoExecuting
	 *            the brokerInfoExecuting to set
	 */
	public static void setBrokerInfoExecuting(String brokerInfoExecuting) {
		PDWorkerInfo.brokerInfoExecuting = brokerInfoExecuting;
	}

	/**
	 * @return the executionReference
	 */
	public static Object getExecutionReference() {
		return executionReference;
	}

	/**
	 * @param executionReference
	 *            the executionReference to set
	 */
	public static void setExecutionReference(Object executionReference) {
		PDWorkerInfo.executionReference = executionReference;
	}

	/**
	 * @return the requestIdExecuting
	 */
	public static long getRequestIdExecuting() {
		return requestIdExecuting;
	}

	/**
	 * @param requestIdExecuting
	 *            the requestIdExecuting to set
	 */
	public static void setRequestIdExecuting(long requestIdExecuting) {
		PDWorkerInfo.requestIdExecuting = requestIdExecuting;
	}

}
